package com.yanwq.sayhi.service;

import com.yanwq.sayhi.bean.User;
import com.yanwq.sayhi.repository.UserRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 作者：yanwq。
 * 日期：2016/1/27。
 */
@Service
public class UserService {

    @Autowired
    private UserRepo repository;

    public User save(User user) {
        return repository.save(user);
    }

    public User findByUsernameAndPassword(String username, String password) {
        return repository.findByUsernameAndPassword(username, password);
    }

    public User findByUuid(String uuid) {
        return repository.findByUuid(uuid);
    }

    public boolean validateToken(String token) {
        return repository.countByToken(token) == 1;
    }

    public boolean hasUsername(String username) {
        return repository.countByUsername(username) > 0;
    }

    public boolean hasPhone(String phone) {
        return repository.countByPhone(phone) > 0;
    }

    public boolean hasNickname(String nickname) {
        return repository.countByNickname(nickname) > 0;
    }
}
